/*
 * Copyright (c) 2024 endless-sky
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef EL_PROTOCOL_COMMAND_HANDLER_BASE_H
#define EL_PROTOCOL_COMMAND_HANDLER_BASE_H

#include <string>
#include <functional>
#include <unordered_map>
#include <nlohmann/json.hpp>

namespace El {
namespace Protocol {

/**
 * @brief 命令处理器基类
 * 提供所有命令处理器共用的基本功能
 */
class CommandHandlerBase {
public:
    CommandHandlerBase() = default;
    virtual ~CommandHandlerBase() = default;

    // 禁止拷贝和赋值
    CommandHandlerBase(const CommandHandlerBase &) = delete;
    CommandHandlerBase &operator=(const CommandHandlerBase &) = delete;

    /**
     * @brief 创建错误响应
     * @param id 请求ID
     * @param code 错误码
     * @param message 错误消息
     * @param data 错误详情（可选）
     * @return 错误响应JSON
     */
    nlohmann::json CreateErrorResponse(const std::string &id,
                                       int code,
                                       const std::string &message,
                                       const nlohmann::json &data = nullptr);

    /**
     * @brief 创建成功响应
     * @param id 请求ID
     * @param result 响应结果
     * @return 成功响应JSON
     */
    nlohmann::json CreateSuccessResponse(const std::string &id, const nlohmann::json &result);
};

} // namespace Protocol
} // namespace El

#endif // EL_PROTOCOL_COMMAND_HANDLER_BASE_H